﻿@model EntryEditViewModel

@{ this.Layout = "~/Views/Shared/Layout.cshtml"; }

@this.Html.RenderMessage()

<div class="sitePath">
	<a title="@this.Model.PageDescription" href="@this.Url.Action("List", new { pageNumber = 1, viewType = this.Model.ViewType, tag = (string)null })">@this.Model.PageName</a>
	>
	@if (this.Model.Id == 0)
	{	
		<a href="@this.Url.Action("New", new { viewType = this.Model.ViewType })" title="@Resources.AddNewEntry">@Resources.NewEntry</a>
	}
	else
	{
		<a href="@this.Url.Action("View", new { viewType = this.Model.ViewType, entryId = this.Model.Id})" title="@this.Model.Title">@this.Model.Title</a>
		<text> > </text>
		<a href="@this.Url.Action("Edit", new { viewType = this.Model.ViewType, entryId = this.Model.Id })" title="@Resources.EditEntry">@Resources.Edit</a>
	}
</div>

<div class="entryEdit">
	@using (this.Html.BeginForm("Edit", "Entries", FormMethod.Post, new { enctype = "multipart/form-data"}))
	{
		<input type="hidden" name="id" value="@this.Model.Id" />
		<input type="hidden" name="viewType" value="@this.Model.ViewType" />
		<div>
			@Resources.Title
		</div>
		<div>
			<textarea rows="0" cols="0" name="title" class="entryTitle @(this.Model.IsTitleValid ? "" : "errorInput")">@this.Model.Title</textarea>
		</div>
		<div>
			@{ this.Html.RenderPartial("EditCommands", 0); }
		</div>
		
		foreach (EntryElementViewModel element in this.Model.Elements)
		{
			<div class="entryElementEdit">
				@this.Html.Partial(element.EditViewName, element)
			</div>
		}

		<div>
			@Resources.Tags
		</div>
		<div class="entryTags">
		@foreach (TagViewModel tag in this.Model.AllTags)
		{ 
			string isChecked = this.Model.Tags.Any(t => t.Code == tag.Code) ? "checked=\"checked\"" : string.Empty ;
			<div style="display:inline-block">
				<input type="checkbox" name="@string.Format("tag_{0}_{1}_{2}", tag.Id, tag.Name, tag.Code)" @isChecked />@tag.Name
			</div>
		}
		</div>
				
		<div class="actionButtons">
			<button name="action" class="linkButton" value="@EntryEditActionType.Save" title="@Resources.SaveEntry">@Resources.Save</button>
			<button name="action" class="linkButton" value="@EntryEditActionType.Preview" title="@Resources.PreviewEntry">@Resources.Preview</button>
			<button name="action" class="linkButton" value="@EntryEditActionType.Cancel" title="@Resources.CancelEditEntry">@Resources.Cancel</button>
		</div>
	}
</div>
@if (this.Model.PreviewEdit)
{
	<hr />	
	this.Html.RenderPartial("ViewEntry", this.Model);
}	